package org.example.dao;

import org.example.db.JDBCUtil;
import org.example.javabean.Admin;
import org.example.javabean.User;

import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDao {
    public User selectOne(String username){
        User user=null;
        try(ResultSet rs=
                    JDBCUtil.getInstance().executeQueryRS("select * from borrow_card "+
                "where "+"username=?",
                new Object[]{username})){
            while(rs.next()){
                user=new User(rs.getString("username"),rs.getString("password"),
                        rs.getString("reader"),rs.getString("header"),rs.getString("cellphone"),
                        rs.getString("email"), rs.getString("describe"));
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
        return user;
    }

    public Admin selectOne(String username,String password){
        Admin admin = null;
        try(ResultSet resultSet = JDBCUtil.getInstance().executeQueryRS("select * from admin where username = ?",new Object[]{username})){
            while (resultSet.next()){
                admin = new Admin(resultSet.getString("username"),resultSet.getString("password"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return admin;
    }
}
